package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.pojo.User;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.beanwx.bo.WxCommentListBO;
import com.cskaoyan.beanwx.bo.WxCommentPostBO;
import com.cskaoyan.beanwx.vo.WxCommentCountVO;
import com.cskaoyan.beanwx.vo.WxCommentListVO;
import com.cskaoyan.beanwx.vo.WxCommentPostVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author liusenbiao
 * @version 1.0
 */
@RequestMapping("/wx/comment")
@RestController
public class WxCommentController {
    @Autowired
    com.cskaoyan.service.CommentService CommentService;

    /**
     * 评论列表展示
     * @param wxCommentListBO 评论请求参数
     * @return BaseRespVO
     */
    @RequestMapping("list")
    public BaseRespVo showCommentList(WxCommentListBO wxCommentListBO){
        WxCommentListVO wxCommentListVO = CommentService.getCommentList(wxCommentListBO);
        return BaseRespVo.ok(wxCommentListVO);
    }

    /**
     * 发表评论
     * @param wxCommentPostBO 评论构造参数
     * @param userId 当前用户id
     * @return BaseRespVO
     */
    @RequestMapping("post")
    public BaseRespVo commentPost(@RequestBody WxCommentPostBO wxCommentPostBO ) {
        Subject subject = SecurityUtils.getSubject();
        //User principal = (User) subject.getPreviousPrincipals().getPrimaryPrincipal();
        User principal = (User) subject.getPrincipals().getPrimaryPrincipal();

        Integer userId = principal.getId();
        WxCommentPostVO wxCommentPostVO = CommentService.postComment(wxCommentPostBO,userId);
        return BaseRespVo.ok(wxCommentPostVO);
    }
    @RequestMapping("count")
    public BaseRespVo wxCommentCount(Integer valueId,Integer type) {
        WxCommentCountVO count = CommentService.countComment(valueId);
        return BaseRespVo.ok(count);
    }
}

